export function isMobile() {
  if (
    navigator.userAgent.match(
      /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i
    )
  ) {
    return true;
  } else {
    return false;
  }
}

export function detectPlatform() {
  var userAgent = navigator.userAgent;
  if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) {
    return "iOS";
  }

  if (/Android/.test(userAgent)) {
    return "Android";
  }

  if (/Windows/.test(userAgent)) {
    return "Windows";
  }

  return "Unknown";
}

export async function lockPortrait() {
  if (detectPlatform() == "iOS" || detectPlatform() == "Android") {
    await document.documentElement.requestFullscreen();
    await screen.orientation.lock("landscape-primary");
  }
}

export async function unlockPortrait() {
  await document.documentElement.requestFullscreen();
  await screen.orientation.unlock();
}
